package com.example.qsindusty.jmm_spline.ContralFragment;


import com.example.qsindusty.jmm_spline.api.ApiManager;
import com.yixin.ystartlibrary.base.BasePresenter;
import com.yixin.ystartlibrary.base.IBaseView;
import com.yixin.ystartlibrary.utils.LogUtils;

import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by Administration on 2018/3/19.
 */

public class ControlPresenter extends BasePresenter implements  Contract.Presenter {
   Contract.View mVeiw ;
    @Override
    public void bindView(IBaseView view) {
        mVeiw = (Contract.View) view;
    }

    @Override
    public void unbindView() {
        dispose();
    }

    @Override
    public void getallGPS(String token) {
        ApiManager.getInstence().getJmmApi().geteAllGPS(token)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<ControlData>() {
                    @Override
                    public void onSubscribe(Disposable d) {
                          //  mVeiw.showLoading();
                    }

                    @Override
                    public void onNext(ControlData jsonElement) {
                        LogUtils.i(jsonElement.toString());
                     mVeiw.getsuccessful(jsonElement);
                    }

                    @Override
                    public void onError(Throwable e) {
                 //   mVeiw.closeLoading();
                    }

                    @Override
                    public void onComplete() {
                       // mVeiw.closeLoading();
                    }
                });
    }

        public void  getSingleGPS(String token,String status ,String orderNum){
        ApiManager.getInstence().getJmmApi().getSingleGPS(token,status,orderNum)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<GPSData>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(GPSData jsonElement) {
                        mVeiw.getsuccessful(jsonElement);
                    }

                    @Override
                    public void onError(Throwable e) {
                        LogUtils.i(e.getMessage().toString());
                    }

                    @Override
                    public void onComplete() {

                    }
                });
        }
}
